<?php
namespace app\models\user;

use basic\BaseModel;
use traits\ModelTrait;

/**
 * 用户的车辆信息
 * Class UserCar
 * @package app\models\user
 */
class UserCar extends BaseModel
{
    use ModelTrait;

    /**
     * 主键的ID
     * @var string
     */
    protected $pk = "id";

    /**
     * 模型的名称
     * @var string
     */
    protected $name = "user_car";

    /**
     * 获取用户的所有车辆
     * @param $uid
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getUserCarList($uid)
    {
        return self::where("wxapp_id", self::$wxapp_id)->where("user_id", $uid)->where("is_del", 0)->select();
    }

    /**
     * 添加
     * @param $uid
     * @param $license_no
     * @return bool
     */
    public function add($uid, $license_no)
    {
        return $this->save([
            "license_no" => $license_no,
            "recent_time" => time(),
            "create_time" => time(),
            "wxapp_id" => self::$wxapp_id,
            "is_del" => 0,
            "user_id" => $uid
        ]);
    }

}